package main


// BlockChain 区块链结构体
//本质上是区块指针类型的数组
type BlockChain struct {
	blockChain []*Block
}

// CreateBlockChain 创建带有一个创世块的区块链
func CreateBlockChain() *BlockChain{
	blockChain := BlockChain{
		blockChain: []*Block{GenesisBlock()},
	}
	return &blockChain
}


// AddBlock 当前区块的前一区块哈希值字段从区块链中获取
func (bc *BlockChain)AddBlock(data string){
	preHash := bc.blockChain[len(bc.blockChain)-1].Hash
	block := CreateBlock(preHash, data)
	bc.blockChain = append(bc.blockChain, block)
}